<?php
include '../Module/newsModule.php';
$p=isset($_REQUEST["p"])?$_REQUEST["p"]:1;
$n=100;
$q=isset($_REQUEST["q"])?$_REQUEST["q"]:"";
$newModule=new newsModule();
$categoryid=isset($_REQUEST["cateid"])?$_REQUEST["cateid"]:null;
$_SESSION["category"]=$categoryid;
?>
<div class="id-list-item-about">
    <div class="mybutton icon disable tooltip" title="Trở Về">
        <div><img src="./images/icon/left1.png"/><span>Trở Về</span></div></div>
    <div class="mybutton icon spaceright tooltip"
         title="Tải Lại"
         onclick="loadhtml('./Controller/?AUnit=04_about<?=($categoryid)?"&id=".$categoryid:""?>',$('#box-content'));">
        <div><img src="./images/icon/arrow_refresh1.png"/><span>Tải Lại</span></div></div>
    <div class="mybutton icon disable tooltip"
         title="Lưu"
         ><div><img src="./images/icon/media_floppy_green.png"/><span>Lưu</span></div></div>
    <div class="mybutton icon tooltip" onclick="loadhtml('./Controller/?AUnit=05_detail&cateid=<?=$categoryid?>',$('#box-content'));;"
         title="Thêm Mới"
         ><div><img src="./images/icon/addg.png"/><span>Thêm Mới</span></div></div>

    <div style="clear: both"></div>
    <table style="width:100%;" class="id-table-manage dt">
        <tr>
            <th class="_tal">Mã Số</th>
            <th class="_tal">Hình Ảnh</th>
            <th class="_tal">Tiêu Đề</th>
            <th class="_tal">Danh Mục</th>
            <th class="_tal">Insert</th>
            <th class="_tal">Update</th>
            <th class="_tal" style="min-width: 120px">#</th>
        </tr>
        <?
        
        $dt=$newModule->getNews($p,$n,$q,$categoryid);
        if($dt==null){
            echo "<tr><td colspan=7>No Data to display.</td></tr>";

        }else foreach ($dt as $row){
            if($row["small_image"]) $small_img=$row["small_image"];
            if($row["image"]) $small_img=$row["image"];
        ?>
        <tr class="id-row-head-<?=$row["id"]?>" >
            <td><?=$row["id"]?></td>
            <td onclick="loadhtml('./Controller/?AUnit=05_detail&cateid=<?=$categoryid?>&id=<?=$row["id"]?>',$('#box-content'));">
                <?
                if($small_img){
                ?>
                <img width="60px" height="40px" src="<?=$small_img?>"/>
                <?
                }
                ?>
            </td>
            <td onclick="loadhtml('./Controller/?AUnit=05_detail&cateid=<?=$categoryid?>&id=<?=$row["id"]?>',$('#box-content'));"><?=$row["title"]?></td>
            <td onclick="loadhtml('./Controller/?AUnit=05_detail&cateid=<?=$categoryid?>&id=<?=$row["id"]?>',$('#box-content'));"><?=$row["categoryname"]?></td>
            <td><?=$row["insert"]?></td>
            <td><?=$row["update"]?></td>
            <td class="">
                <?
                if(isset($row["delete"])){
                ?>

                <span style="color:red">Xóa lúc <?=$row["delete"]?></span>
                <div class="icon16 hover50 tooltip" title="Khôi Phục" onclick="restoreItem('<?=$row["id"]?>');">
                        <img src="./images/icon/gtk_undelete.png"/>
                </div>
                <?
                }
                if($row["lock"])
                        echo "<img class='tooltip' src='./images/icon/16/locked.png' title='This item is locked'/>";
                ?>
                <span class="action">
                    <?
                    if(!isset($row["delete"]) && !$row["lock"]){
                    ?>
                    <div class="icon16 hover50 tooltip" title="Xóa" onclick="deleteItem('<?=$row["id"]?>');">

                        <img src="./images/icon/16/edit_delete.png"/>
                    </div>
                    <?
                    }
                    
                    
                    ?>
                </span>
            </td>
        </tr>

        <?
        }
        ?>
    </table>
    <div style="clear: both"></div>
    <div class="mybutton icon disable tooltip" title="Trở Về">
        <div><img src="./images/icon/left1.png"/><span>Trở Về</span></div></div>
    <div class="mybutton icon spaceright tooltip"
         title="Tải Lại"
         onclick="loadhtml('./Controller/?AUnit=04_about<?=($categoryid)?"&id=".$categoryid:""?>',$('#box-content'));">
        <div><img src="./images/icon/arrow_refresh1.png"/><span>Tải Lại</span></div></div>
    <div class="mybutton icon disable tooltip"
         title="Lưu"
         ><div><img src="./images/icon/media_floppy_green.png"/><span>Lưu</span></div></div>
    <div class="mybutton icon tooltip" onclick="loadhtml('./Controller/?AUnit=05_detail&cateid=<?=$categoryid?>',$('#box-content'));;"
         title="Thêm Mới"
         ><div><img src="./images/icon/addg.png"/><span>Thêm Mới</span></div></div>

    <div style="clear: both"></div>

    <div style="clear: both"></div>
    
    <script>
        
        $(document).ready(function(){
            $(".tooltip").tipTip({defaultPosition:"top", edgeOffset: 10});
            
        });
        function restoreItem(id){
            if(!confirm("Bạn muốn khôi phục?")) return;
            var surl="./Controller/";
            var sdata={
                    "controller":"NewController",
                    "action":"restore",
                    "id":id
            };
            jQuery.ajax({
                    type:"POST", 
                    data:sdata, 
                    dataType:"text", 
                    url:surl, 
                    success: function (data){
                        if(data=="true"){
                            showmsg("Đã khôi phục.",2000);

                            var str="<span class=\"action\">";
                            str+="      <div class=\"icon16 hover50 tooltip\" title=\"Xóa\" onclick=\"deleteItem('"+id+"');\">";
                            str+="          <img src=\"images/icon/16/edit_delete.png\"/>";
                            str+="      </div>";
                            str+="   </span>";
                            $(".id-row-head-"+id).find("td:last-child").html(str);
                        }else{
                            showerrorbox(null,data);
                        }

                    },
                    error: function (xhr, ajaxOptions, thrownError){
                            showerrorbox(null,"<b>Status</b>:"+xhr.status+"<br/><b>ThrownError</b>:"+thrownError,5000);

                    }
            });
        }
        function deleteItem(id){
            if(!confirm("Bạn muốn xóa?")) return;
            var surl="./Controller/";
            var sdata={
                    "controller":"NewController",
                    "action":"delete",
                    "id":id
            };
            jQuery.ajax({
                    type:"POST", 
                    data:sdata, 
                    dataType:"text", 
                    url:surl, 
                    success: function (data){
                        if(data=="true"){
                            showmsg("Đã xóa.",2000);
                            var str="<span style=\"color:red\">Đã xóa</pan>";
                            str+="   <div class=\"icon16 hover50 tooltip\" title=\"Khôi Phục\" onclick=\"restoreItem('"+id+"');\">";
                            str+="      <img src=\"images/icon/gtk_undelete.png\"/>";
                            str+="   </div>";
                            $(".id-row-head-"+id).find("td:last-child").html(str);

                        }else{
                            showerrorbox(null,data);
                        }

                    },
                    error: function (xhr, ajaxOptions, thrownError){
                            showerrorbox(null,"<b>Status</b>:"+xhr.status+"<br/><b>ThrownError</b>:"+thrownError,5000);

                    }
            });
        }
    </script>
</div>
<?
//include "../Admin/08_gioithieu.php";
?>
